#!/bin/sh 

#  upload.sh
#  Fri Feb 12 00:55:59 2010
#  Copyright  2010  mk67
#  <rmk677@gmail.com>
svn_dir="/home/mike/Dev/svn/the-nvidia-swiss-knife/"
## Script colours Vars.
t='\e[0;39m'	#default terminal colour
r='\e[1;31m'	#red
v='\e[1;32m'	#green
y='\e[1;36m'	#cyan
j='\e[1;33m'	#yellow
# config file
#. $svn_dir/user_config
#touch user_config
upload_file(){
. $svn_dir/user_config
ls $svn_dir/user_config >> /dev/null
if [[ $? -eq 0 ]] ; then
	scp_user="$user"
	scp_project="$project"
	scp_pwd="$psswd"
	echo -e "$v   Nom du fichier:\n   $y==>$j \c"
	read -e upload
	echo -e "$v   Labels du fichier:\n   (Featured,Type-Executable,OpSys-Linux)\n   $y==>$j \c"
	read label
	echo -e "$v   Commentaires:\n   $y==>$j \c"
	read -e summary ; echo -e "$y"
	python googlecode_upload.py -s "$summary" -p $scp_project --labels=$label -u $scp_user -w $scp_pwd $upload
	echo -e "$t"
	exit 0
else
	echo -e "\n$r  Config file is ot in your path.$t"
	exit 0
fi
}
ls $svn_dir/user_config >> /dev/null
if [ $? -eq 0 ] ; then
	upload_file
else
	if [[ $? -ne 0 ]] ; then
		#if [[ $? -eq 0 ]] ; then
		#	rm -f $svn_dir/user_config
		#fi
		echo -e "$y WELCOME TO THE EASY GOOGLE CODE UPLOADER\f This your first start."
		echo -e "$y Answer to the questions now. It will be run just once;\n I never ask you this again.\f"
		echo -e "$y Fill entry to complete googlecode user config file."
		echo -e "$v Your project path: $j\c"
		read -e svn_dir ; sed -i "7csvn_dir=\"$svn_dir\"" upload.sh
		echo -e "$v User name: $j\c"
		read user ; echo "user=$user" >> user_config
		echo -e "$v Project name: $j\c"
		read project ; echo "project=$project" >> user_config
		echo -e "$v Password: $j\c"
		read psswd ; echo "psswd=$psswd" >> user_config
		chmod 644 $svn_dir/user_config
		ls $svn_dir/googlecode_upload.py >> /dev/null
		if [[ $? -ne 0 ]] ; then
			echo -e "$y Let's download googlecode_upload.py file now.$v\f"
			wget http://support.googlecode.com/svn/trunk/scripts/googlecode_upload.py
		else
			echo -e "$v Googlecode_upload.py is already present.\n Nothing to do.\f$t"
		fi
		if [ $? -eq 0 ] ; then
			echo -e "$r\n DONE ..."
		else
			echo -e "$v Download didn't work, check you connection.\n and restart the script.\f$t"
			exit 0
		fi
		echo -e "$v Restart upload.sh script now.\f$t"
		exit 0
	fi
fi
exit 0